package clientmain.auth.basic;


import java.util.HashMap;
import java.util.Map;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor;
import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;

public class DynamicClient {
	public static void main(String[] args) {
		JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance(); 
		Client client = dcf.createClient("http://10.71.58.54:9999/hysoft?wsdl");
		
        Map<String, Object> outProps = new HashMap<String, Object>();
        outProps.put("action", "UsernameToken Timestamp");

        outProps.put("passwordType", "PasswordDigest");
        outProps.put("user", "abcd");
        outProps.put("passwordCallbackClass", "com.hysoft.cxf.ws.auth.basic.UTPasswordCallback");


        Map<String, Object> inProps = new HashMap<String, Object>();
        inProps.put("action", "UsernameToken Timestamp");
        inProps.put("passwordType", "PasswordText");
        inProps.put("passwordCallbackClass", "com.hysoft.cxf.ws.auth.basic.UTPasswordCallback");
		
        client.getInInterceptors().add(new WSS4JInInterceptor(inProps));
        client.getOutInterceptors().add(new WSS4JOutInterceptor(outProps));
        
		Object[] res = null;
		try {
			res = client.invoke("sayHi","kk");
//			res = client.invoke("getCatsByUser","孙悟空");
//			res = client.invoke("getAllCats1");
//			res = client.invoke("getAllCats2");
//			res = client.invoke("getAllCats3");
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("Echo response: " + res[0].toString());
	}
}
